<template>
	<view class="content">
		<view class="loading">

		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {

			}
		},
		onLoad() {
			this.getUserInfoRes()
		},
		methods: {
			getUserInfoRes() {
				uni.showLoading({
					title: '正在加载数据',
					mask: true
				})
				var ua = navigator.userAgent.toLowerCase();
				if (ua.match(/MicroMessenger/i) == "micromessenger") {
					let code = GetQueryString("code")
					console.log('code', code); //哪这个code去服务端换userInfo
					this.code = code
					uniCloud.callFunction({
						name: 'getUserInfo',
						data: {
							code: this.code
						}
					}).then((res) => {
						console.log('getUserInfo', res)
						let userInfo = res.result.data
						// uni.setStorageSync('userInfo',res.result.data)
						uniCloud.callFunction({
							name: 'saveUser',
							data: userInfo
						}).then((res1) => {
							console.log('res1', res1)
							uni.hideLoading()

							uni.setStorageSync('userInfo', res1.result.data[0])
							uni.setStorageSync('openID', res1.result.data[0].openid)

							uni.redirectTo({
								url: '../login/login'
							})


						})
					}).catch((res) => {
						uni.hideLoading()
						console.log(res)

					})
				} else {
					uni.hideLoading()
					console.log('不在微信里面不能微信登录');
					return false

					// return false;
				}

				function GetQueryString(name) //获取参数
				{
					var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
					var r = window.location.search.substr(1).match(reg); //search,查询？后面的参数，并匹配正则
					if (r != null) return unescape(r[2]);
					return null;
				}
			},

		}
	}
</script>

<style lang="scss" scoped>
	page {
		background: url('@/static/bg.jpg') no-repeat center top;
		background-size: 100% auto;
	}

	.loading {
		width: 750rpx;
		height: 1252rpx;
		background: url('@/static/loading.png') no-repeat center center;
		background-size: 100% auto;
		margin-top: 136rpx;
	}
</style>
